<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://www.zkingsoft.com" prefix="matrix"%>
<%@ page import="com.zkingsoft.constance.SystemConstance"%>
<%@ page import="com.zkingsoft.util.WebUtil"%>
<%
	String isShowHotel = "true";
	String login_plat = String.valueOf(WebUtil.getSessionAttribute(SystemConstance.LOGIN_PLAT));
	if(SystemConstance.PLAT_HOTEL.equals(login_plat)) {
		isShowHotel = "false";
	}

	String isFactoryLogin = "false";
	if(SystemConstance.PLAT_FACTORY.equals(login_plat)) {
		isFactoryLogin = "true";
	}
	
	String isCompanyLogin = "false";
	if(SystemConstance.PLAT_COMPANY.equals(login_plat)) {
		isCompanyLogin = "true";
	}
%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<c:set var="isShowHotel" value="<%=isShowHotel%>" />
<c:set var="isFactoryLogin" value="<%=isFactoryLogin%>" />
<c:set var="isCompanyLogin" value="<%=isCompanyLogin%>" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/plugin/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
<style type="text/css">
.huanhang {
	word-break: break-all;
	word-wrap: break-all;
}

#serchform .input-group {
	margin: 5px 0;
}

#serchform .select2, .select2-selection--single {
	height: 34px !important;
	width: 100% !important;
}

#serchform .input-group-addon {
	font-weight: 700;
	min-width: 100px;
	border-right: 0 !important;
	background: #fbfbfb;
	padding: 0;
	width: 1% !important;
}

#serchform .m-r-10 {
	margin-right: 10px;
}
</style>
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<!-- 搜索框部分start -->
		<matrix:btn value="LinOrder:search">
			<div class="row">
				<div class="col-sm-12">
					<form class="form-inline" id="serchform">
						<div class="row">
							<div class="col-sm-3">
								<div class="input-group">
									<span class="input-group-addon">月份</span> <select name="month"
										class="form-control autoFull select2"
										data-url="${path}/admin/linOrder/getMonth" data-value="month"
										data-filed="month">
										<option value="">请选择月份</option>
									</select>
								</div>
							</div>
							<c:if test="${isCompanyLogin eq 'true'}">
							<div class="col-sm-3" align="center">
								<div class="input-group">
									<span class="input-group-addon">订单类型</span>
									<select id="orderType" class="form-control" onchange="changeOrderType()">
										<option value="hotel">酒店</option>
										<option value="factory">工厂</option>
									</select>
								</div>
							</div>
							</c:if>
							<c:if test="${isShowHotel eq 'true'}">
							<div class="col-sm-3">
								<div class="input-group">
									<span class="input-group-addon">酒店</span> <select name="hotelId"
										class="form-control autoFull select2"
										data-url="${path}/admin/linHotel/showAll" data-value="hotelId"
										data-filed="hotelName">
										<option value="">请选择酒店</option>
									</select>
								</div>
							</div>
							</c:if>
							<div class="col-sm-3">
								<div class="input-group" style="top: 3px;">
									<button onclick="myGrid.serchData()" type="button"
										class="btn btn-info btn-sm m-r-10">
										<i class="fa fa-search "></i> 搜索
									</button>
									<button onclick="myReset('#serchform');" type="button"
										class="btn btn-info btn-sm m-r-10">
										<i class="fa fa-refresh "></i> 重置
									</button>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</matrix:btn>
		<!-- 搜索框部分en -->
		<div class="ibox-content radius-5 mt-5 mpanel">
			<div class="row">
				<div class="col-sm-12">
					<div class="option-bar"></div>
					<table id="mgrid">
						<thead>
							<tr>
								<th data-formatter="MGrid.indexfn" data-align="center"
									data-width="30px" data-field="index">序号</th>
								<th data-field="month">月份</th>
								<th data-field="totalNumMonth">总数量</th>
								<th data-field="totalPriceMonth" data-formatter="setOrderPrice">总价格</th>
								<th data-field="totalLossMonth">总损耗</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript"
		src="${path }/resource/js/systools/MJsBase.js"></script>
	<script type="text/javascript">
		function setOrderPrice(value, row, index) {
			if("<%=isFactoryLogin%>" == 'true') {
				return value;
			} else if("<%=isCompanyLogin%>" == 'true'){
				if($('#orderType').val() == 'factory') {
					return value;
				} else {
					return row.realPriceMonth;
				}
			} else {
				return row.realPriceMonth;
			}
		}
	</script>
	<script type="text/javascript">
		$(".select2").select2();
		MTools.autoFullSelect();
		var myGrid;
		$(function() {
			var delUrl = "";
			<matrix:btn value="LinOrder:del">
			delUrl = "${path}/admin/linOrder/del";
			</matrix:btn>
			myGrid = MGrid.initGrid({
						url : "${path}/admin/linOrder/getOrderStatistics",
						delUrl : delUrl,
						onClickCell : function(field, value, row, $element) {
							var hotelId = "";
							if($('select[name="hotelId"]').val()) {
								hotelId = "&hotelId=" + $('select[name="hotelId"]').val();
							}
							var orderType = "";
							if("<%=isCompanyLogin%>" == 'true'){
								orderType = "&orderType=" + $('#orderType').val();
							}
							layer.full(
								layer.open({
									type : 2,
									title : "查看统计 " + row.month,
									area : [ MUI.SIZE_L, '400px' ],
									maxmin : true,
									content : [ '${path}/admin/linOrder/getStatisticsDetail?month='
											+ row.month + hotelId + orderType ]
								}));
						},
					});
		});
		
		function changeOrderType(){
			$('#mgrid').bootstrapTable('refresh', {
				silent : true
			});
		}
		
		function myReset(formId) {
			$(':input', formId).not(':button, :submit, :reset, :hidden')
					.val('').removeAttr('value').removeAttr('checked')
					.removeAttr('selected');
			$(".select2", formId).val("").trigger("change");
			
			$('#orderType').val('hotel');
		}
	</script>
</body>
</html>
